package com.qhsolution.adapter;

import com.qhsolution.bdict.R;
import com.qhsolution.object.Currency;

import java.util.ArrayList;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class CurrencyArrayAdapter extends ArrayAdapter<Currency> {
	Activity context = null;
	ArrayList<Currency> myArray = null;
	int layoutId;
	public static final String KEY_ID = "id";

	public CurrencyArrayAdapter(Activity context, int layoutId, ArrayList<Currency> arr) {
		super(context, layoutId, arr);
		this.context = context;
		this.layoutId = layoutId;
		this.myArray = arr;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		LayoutInflater inflater = context.getLayoutInflater();
		convertView = inflater.inflate(layoutId, null);
		if (myArray.size() > 0 && position >= 0) {
			final TextView txtIdCurrency = (TextView) convertView
					.findViewById(R.id.txtIdCurrency);
			final TextView txtCurrencyName = (TextView) convertView
					.findViewById(R.id.txtCurrencyName);
			final TextView txtCurrencyCode = (TextView) convertView
					.findViewById(R.id.txtCurrencyCode);
			final TextView txtCurrencySymbol = (TextView) convertView
					.findViewById(R.id.txtCurrencySymbol);
			final Currency currency = myArray.get(position);
			
			txtIdCurrency.setText(String.valueOf(currency.getId()));			
			txtCurrencyName.setText(currency.getName());
			txtCurrencyCode.setText(currency.getCode());
			txtCurrencySymbol.setText(currency.getSymbol());
			
		}
		return convertView;
	}
}
